﻿using System;
using Eneta.Portal.Forum.Core.Domain.Collections;
using Eneta.Portal.Forum.Core.Service.Application;

namespace Eneta.Portal.Forum.Core.Domain.Entities
{
    public class Topic : DomainObject
    {
        // Fields
        private MessageCollection _messages;

        // Methods
        private Topic()
        {
        }

        public Topic(int forumId, string name)
        {
            ForumId = forumId;
            Name = name;
        }

        public Topic(int id, int forumId, string name)
        {
            Id = id;
            ForumId = forumId;
            Name = name;
        }

        public ForumUser Author { get; set; }
        public int ForumId { get; set; }
        public DateTime LastPost { get; set; }
        public string AuthorLoginName { get; set; }

        public MessageCollection Messages
        {
            get
            {
                if (_messages == null)
                {
                    _messages = RepositoryRegistry.MessageRepository.GetByTopicId(Id);
                }
                return _messages;
            }
        }

        public int NumPosts { get; set; }

        public int Replies
        {
            get
            {
                return (NumPosts - 1);
            }
        }

        public int TopicStarterId { get; set; }
        public int Views { get; set; }
    }
}
